package com.tree.redisson.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName com.tree.redisson
 * Description: <类功能描述>.
 * <br>
 * @Author frankzsliu
 * @Date 2020/11/6 11:26 下午
 * @Version 1.0
 */
@Configuration
public class RedissonConfig {
//    @Value("${redisson.json}")
//    private String configJson;

//    public String getConfigJson() {
//        return configJson;
//    }

//    @Bean(destroyMethod = "shutdown")
//    public RedissonClient redisson() throws IOException{
//        RedissonClient redisson = Redisson.create(Config.fromYAML(new ClassPathResource("redisson-single.yml").getInputStream()));
//        return redisson;
//    }

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient(){
//        List<String> nodes = clusterConfigurationProperties.getNodes();
//        String[] nodesArr =  {"redis://9.134.119.89:18889"};
//        "redis://9.134.119.89:18889","redis://9.134.117.122:18880","redis://9.134.119.89:18880",
//                "redis://9.134.124.41:18880","redis://9.134.117.122:18881","redis://9.134.119.89:18881"
//        String[] nodesArr = nodes.stream().map(s->"redis://"+s).toArray(String[]::new);
        Config config = new Config();
        config.useSingleServer().setAddress("redis://localhost:6379")
//                .addNodeAddress("redis://localhost:6379")
//                .setPassword(clusterConfigurationProperties.getPassword())
        ;
        return Redisson.create(config);
    }

//    @Bean
//    public RedissonClient getRedisson()
//    {
//        Config config = new Config();
//        config.useSingleServer()
//                .setAddress("redis://192.168.6.52:6379").setPassword("123456")
//                .setRetryInterval(5000)
//                .setTimeout(10000)
//                .setConnectTimeout(10000);
//        return Redisson.create(config);
//    }

}
